/*
 * FlagBotFactory.java
 * 
 * Created on Jul 3, 2007, 2:32:25 PM
 * 
 * Copyright (c) 2007 Daniel Gronau
 *
 * This file is part of KanjiTori.
 *
 * KanjiTori is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * KanjiTori is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

package kanjitori.graphics.bot;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;
import javax.swing.ImageIcon;
import kanjitori.util.Cache;

/**
 *
 * @author DGronau
 */
public class FlagBotFactory implements BotFactory {

    private final static String CORPUS_IMAGE = "corpusImage";
    private String corpusImage = "data/corpus.png";
    
    public void setParams(Map<String, String> map) {
        String tempCorpusImage = map.get(CORPUS_IMAGE);
        if (tempCorpusImage != null) { corpusImage = tempCorpusImage; }       
    }
    
    public Map<String, String> getParams(){
        Map<String, String> map = new HashMap<String, String>();
        map.put(CORPUS_IMAGE, corpusImage);
        return map;
    }

    public Bot get(String key) {
        return new FlagBot(key);
    }
    
 private class FlagBot extends AbstractBoxBot implements Bot {
    
    /** Creates a new instance of Bot 
     * @param value 
     */
    public FlagBot(String value) {
        super(value);
    }
    
    Image getImage(String fileName) {
        
        BufferedImage bi = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB);
        Graphics2D bg = (Graphics2D) bi.getGraphics();
        Image corpus = Cache.getImage(corpusImage);
        bg.drawImage(corpus, 0, 0, null);
        
        Image flag = new ImageIcon(fileName).getImage();
        int x = (256 - flag.getWidth(null)) / 2;
        int y = (256 - flag.getHeight(null)) / 2;
        bg.drawImage(flag, x, y, null);
        bg.dispose();
        return bi;
    }    
    
 }

}
